package com.zhang.mapper;

import com.zhang.pojo.Category;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;
/**文章分类相关接口
 * @program: big_event
 * @description: TODO
 * @author: Mr.Zhang
 * @create: 2024-03-22 13:24
 **/
@Mapper
public interface CategoryMapper {

    /**
     * 新增文章分类
     * @param category
     */
    @Insert("insert into category(category_name,category_alias,create_user,create_time,update_time) " +
            "values(#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime})")
    void add(Category category);

    /**
     * 查询所有文章分类
     * @param userId
     * @return
     */
    @Select("select * from category where create_user = #{userId}")
    List<Category> list(Integer userId);

    /**
     * 根据ID查询分类信息
     * @param id
     * @return
     */
    @Select("select * from category where id = #{id}")
    Category findByid(Integer id);


    /**
     * 更新分类
     * @param category
     */
    @Update("update category set category_name = #{categoryName}," +
            "category_alias = #{categoryAlias},update_time = #{updateTime}" +
            "where id = #{id}")
    void update(Category category);

    /**
     * 根据ID删除文章分类
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void delete(Integer id);
}
